package com.nsl.Kotlin

import kotlin.random.Random

class PokerSuit(var suit : String, var tag :Int)
class PokerNumber (var number : String, var tag :Int)
class Poker(var numberObj : PokerNumber,var suitObj : PokerSuit){
    fun display(){ print(this.numberObj.number+this.suitObj.suit) }
}

class PokerM {
    // 成员属性
    val pokers : ArrayList<Poker> = arrayListOf()//存储所有的 Poker
    val numbers = arrayOf("2","3","4","5","6","7","8","9","10","J","Q","K","A")
    val suits = arrayOf("♦","♣","♥","♠")

    // 初始化内容：创建一副牌
    init {
        for((i,number) in numbers.withIndex()){
            for ((j,suit) in suits.withIndex()){
                //创建点数和花色的对象
                pokers.add(Poker(PokerNumber(number,i),PokerSuit(suit,j)))
            }
        }
        //pokers.add(Poker(PokerNumber("Joker",10),PokerSuit("*Red",6)))
        //pokers.add(Poker(PokerNumber("Joker",10),PokerSuit("*Black",5)))
    }
    //成员函数
    fun getPoker(): Poker {
        //随机抽取一张牌
        val index = Random.nextInt(pokers.size)
        var poker:Poker = pokers[index]
        pokers.removeAt(index)
        return poker
    }

    fun distributePokers(players: ArrayList<Player>) {
        //发牌器
        println("性感荷官在线发牌...")
        for (i in 0..3 ){
            // 给场上的玩家发牌
            players[i].poker=this.getPoker()
        }
    }

    fun comparePokers(poker1: Poker, poker2: Poker): Boolean {
        print("您的手牌为：")
        poker1.display()
        print("  对方的手牌为：")
        poker2.display()
        return if (poker1.numberObj.tag == poker2.numberObj.tag) {
            if (poker1.suitObj.tag > poker2.suitObj.tag) {
                return true
            } else {
                return false
            }
        } else if (poker1.numberObj.tag > poker2.numberObj.tag) {
            return true
        } else {
            return false
        }
    }
}